{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-06-03T01:50:41.063328Z",
     "start_time": "2025-06-03T01:50:41.045440Z"
    }
   },
   "source": [
    "import json\n",
    "\n",
    "from pyecharts.charts import Map\n",
    "from pyecharts import options as opts\n",
    "# 从json格式的文件中读取需要渲染的数据\n",
    "with open('yq.json','rt',encoding='utf8') as f:\n",
    "    file_data = json.load(f)\n",
    "    # areaTree\n",
    "    area_tree_dict = file_data['areaTree'][0]\n",
    "    # children\n",
    "    area_tree_dict_children = area_tree_dict['children']\n",
    "    # 遍历children  list\n",
    "    china_map_data = []\n",
    "    for child in area_tree_dict_children:\n",
    "        province_name = child['name']\n",
    "        if province_name in ['北京','天津','重庆','上海']:\n",
    "            province_name+='市'\n",
    "        elif province_name in ['香港','澳门']:\n",
    "            province_name+='特别行政区'\n",
    "        elif province_name =='新疆':\n",
    "            province_name+='维吾尔自治区'\n",
    "        elif province_name =='广西':\n",
    "            province_name+='壮族自治区'\n",
    "        elif province_name =='宁夏':\n",
    "            province_name+='回族自治区'\n",
    "        elif province_name in ['西藏','内蒙古']:\n",
    "            province_name+='自治区'\n",
    "        else:\n",
    "            province_name+='省'\n",
    "        province_tuple =(province_name,child[\"total\"][\"confirm\"])\n",
    "        china_map_data.append(province_tuple)\n",
    "    print(china_map_data)\n",
    "        "
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[('台湾省', 15880), ('江苏省', 1576), ('云南省', 982), ('河南省', 1518), ('上海市', 2408), ('湖南省', 1181), ('湖北省', 68286), ('广东省', 2978), ('香港特别行政区', 12039), ('福建省', 773), ('浙江省', 1417), ('山东省', 923), ('四川省', 1179), ('天津市', 445), ('北京市', 1107), ('陕西省', 668), ('广西壮族自治区', 289), ('辽宁省', 441), ('重庆市', 603), ('澳门特别行政区', 63), ('甘肃省', 199), ('山西省', 255), ('海南省', 190), ('内蒙古自治区', 410), ('吉林省', 574), ('黑龙江省', 1613), ('宁夏回族自治区', 77), ('青海省', 18), ('江西省', 937), ('贵州省', 147), ('西藏自治区', 1), ('安徽省', 1008), ('河北省', 1317), ('新疆维吾尔自治区', 980)]\n"
     ]
    }
   ],
   "execution_count": 5
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-03T01:53:07.874234Z",
     "start_time": "2025-06-03T01:53:07.856851Z"
    }
   },
   "cell_type": "code",
   "source": [
    "map = (\n",
    "    Map()\n",
    "    .add('', china_map_data, \"china\")\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(title=\"中国地图示例\"),  # 设置标题\n",
    "        visualmap_opts=opts.VisualMapOpts(max_=1500, is_piecewise=True)  # 设置视觉映射\n",
    "    )\n",
    ")\n",
    "map.render_notebook()"
   ],
   "id": "9a600396d9ae6504",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x1477cf41900>"
      ],
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/v5/echarts.min', 'china':'https://assets.pyecharts.org/assets/v5/maps/china'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"ba6fb3789c9c4b30973ef6f61563397d\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts', 'china'], function(echarts) {\n",
       "                var chart_ba6fb3789c9c4b30973ef6f61563397d = echarts.init(\n",
       "                    document.getElementById('ba6fb3789c9c4b30973ef6f61563397d'), 'white', {renderer: 'canvas'});\n",
       "                var option_ba6fb3789c9c4b30973ef6f61563397d = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"aria\": {\n",
       "        \"enabled\": false\n",
       "    },\n",
       "    \"color\": [\n",
       "        \"#5470c6\",\n",
       "        \"#91cc75\",\n",
       "        \"#fac858\",\n",
       "        \"#ee6666\",\n",
       "        \"#73c0de\",\n",
       "        \"#3ba272\",\n",
       "        \"#fc8452\",\n",
       "        \"#9a60b4\",\n",
       "        \"#ea7ccc\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"map\",\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"margin\": 8,\n",
       "                \"valueAnimation\": false\n",
       "            },\n",
       "            \"map\": \"china\",\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u53f0\\u6e7e\\u7701\",\n",
       "                    \"value\": 15880\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6c5f\\u82cf\\u7701\",\n",
       "                    \"value\": 1576\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u4e91\\u5357\\u7701\",\n",
       "                    \"value\": 982\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6cb3\\u5357\\u7701\",\n",
       "                    \"value\": 1518\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u4e0a\\u6d77\\u5e02\",\n",
       "                    \"value\": 2408\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6e56\\u5357\\u7701\",\n",
       "                    \"value\": 1181\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6e56\\u5317\\u7701\",\n",
       "                    \"value\": 68286\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5e7f\\u4e1c\\u7701\",\n",
       "                    \"value\": 2978\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u9999\\u6e2f\\u7279\\u522b\\u884c\\u653f\\u533a\",\n",
       "                    \"value\": 12039\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u798f\\u5efa\\u7701\",\n",
       "                    \"value\": 773\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6d59\\u6c5f\\u7701\",\n",
       "                    \"value\": 1417\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5c71\\u4e1c\\u7701\",\n",
       "                    \"value\": 923\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u56db\\u5ddd\\u7701\",\n",
       "                    \"value\": 1179\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5929\\u6d25\\u5e02\",\n",
       "                    \"value\": 445\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5317\\u4eac\\u5e02\",\n",
       "                    \"value\": 1107\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u9655\\u897f\\u7701\",\n",
       "                    \"value\": 668\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5e7f\\u897f\\u58ee\\u65cf\\u81ea\\u6cbb\\u533a\",\n",
       "                    \"value\": 289\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u8fbd\\u5b81\\u7701\",\n",
       "                    \"value\": 441\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u91cd\\u5e86\\u5e02\",\n",
       "                    \"value\": 603\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6fb3\\u95e8\\u7279\\u522b\\u884c\\u653f\\u533a\",\n",
       "                    \"value\": 63\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u7518\\u8083\\u7701\",\n",
       "                    \"value\": 199\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5c71\\u897f\\u7701\",\n",
       "                    \"value\": 255\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6d77\\u5357\\u7701\",\n",
       "                    \"value\": 190\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5185\\u8499\\u53e4\\u81ea\\u6cbb\\u533a\",\n",
       "                    \"value\": 410\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5409\\u6797\\u7701\",\n",
       "                    \"value\": 574\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u9ed1\\u9f99\\u6c5f\\u7701\",\n",
       "                    \"value\": 1613\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5b81\\u590f\\u56de\\u65cf\\u81ea\\u6cbb\\u533a\",\n",
       "                    \"value\": 77\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u9752\\u6d77\\u7701\",\n",
       "                    \"value\": 18\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6c5f\\u897f\\u7701\",\n",
       "                    \"value\": 937\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u8d35\\u5dde\\u7701\",\n",
       "                    \"value\": 147\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u897f\\u85cf\\u81ea\\u6cbb\\u533a\",\n",
       "                    \"value\": 1\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5b89\\u5fbd\\u7701\",\n",
       "                    \"value\": 1008\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6cb3\\u5317\\u7701\",\n",
       "                    \"value\": 1317\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u65b0\\u7586\\u7ef4\\u543e\\u5c14\\u81ea\\u6cbb\\u533a\",\n",
       "                    \"value\": 980\n",
       "                }\n",
       "            ],\n",
       "            \"roam\": true,\n",
       "            \"aspectScale\": 0.75,\n",
       "            \"nameProperty\": \"name\",\n",
       "            \"selectedMode\": false,\n",
       "            \"zoom\": 1,\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 2,\n",
       "            \"seriesLayoutBy\": \"column\",\n",
       "            \"datasetIndex\": 0,\n",
       "            \"mapValueCalculation\": \"sum\",\n",
       "            \"showLegendSymbol\": true,\n",
       "            \"emphasis\": {}\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\"\n",
       "            ],\n",
       "            \"selected\": {},\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14,\n",
       "            \"backgroundColor\": \"transparent\",\n",
       "            \"borderColor\": \"#ccc\",\n",
       "            \"borderRadius\": 0,\n",
       "            \"pageButtonItemGap\": 5,\n",
       "            \"pageButtonPosition\": \"end\",\n",
       "            \"pageFormatter\": \"{current}/{total}\",\n",
       "            \"pageIconColor\": \"#2f4554\",\n",
       "            \"pageIconInactiveColor\": \"#aaa\",\n",
       "            \"pageIconSize\": 15,\n",
       "            \"animationDurationUpdate\": 800,\n",
       "            \"selector\": false,\n",
       "            \"selectorPosition\": \"auto\",\n",
       "            \"selectorItemGap\": 7,\n",
       "            \"selectorButtonGap\": 10\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"enterable\": false,\n",
       "        \"confine\": false,\n",
       "        \"appendToBody\": false,\n",
       "        \"transitionDuration\": 0.4,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5,\n",
       "        \"order\": \"seriesAsc\"\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"text\": \"\\u4e2d\\u56fd\\u5730\\u56fe\\u793a\\u4f8b\",\n",
       "            \"target\": \"blank\",\n",
       "            \"subtarget\": \"blank\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"textAlign\": \"auto\",\n",
       "            \"textVerticalAlign\": \"auto\",\n",
       "            \"triggerEvent\": false\n",
       "        }\n",
       "    ],\n",
       "    \"visualMap\": {\n",
       "        \"show\": true,\n",
       "        \"type\": \"piecewise\",\n",
       "        \"min\": 0,\n",
       "        \"max\": 1500,\n",
       "        \"inRange\": {\n",
       "            \"color\": [\n",
       "                \"#50a3ba\",\n",
       "                \"#eac763\",\n",
       "                \"#d94e5d\"\n",
       "            ]\n",
       "        },\n",
       "        \"calculable\": true,\n",
       "        \"inverse\": false,\n",
       "        \"splitNumber\": 5,\n",
       "        \"hoverLink\": true,\n",
       "        \"orient\": \"vertical\",\n",
       "        \"padding\": 5,\n",
       "        \"showLabel\": true,\n",
       "        \"itemWidth\": 20,\n",
       "        \"itemHeight\": 14,\n",
       "        \"borderWidth\": 0\n",
       "    }\n",
       "};\n",
       "                chart_ba6fb3789c9c4b30973ef6f61563397d.setOption(option_ba6fb3789c9c4b30973ef6f61563397d);\n",
       "        });\n",
       "    </script>\n"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 7
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "fdc9c630e272ed27"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
